from django.db import models


# Create your models here.

class Category(models.Model):
    name = models.CharField(max_length=20, verbose_name="分类")
    pic = models.ImageField(upload_to="static/pic", null=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = "category"
        verbose_name = "分类表"
        verbose_name_plural = "分类名"


class Goods(models.Model):
    # 商品名 价格  首图  简介  详情  单位  分类  库存

    name = models.CharField("商品名", max_length=20)
    price = models.DecimalField("商品价格", max_digits=8, decimal_places=2)
    desc = models.CharField("简介", max_length=200)
    unit = models.CharField("单位", max_length=20)
    store = models.IntegerField("库存")
    pic = models.ImageField("首图", upload_to="static/pic")
    content = models.TextField("详情")
    cate = models.ForeignKey(Category, on_delete=models.CASCADE, verbose_name="所属分类")

    class Meta:
        db_table = 'goods'
        verbose_name = "商品表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name
